#ifndef PROTOCOL_WAYLAND_H
#define PROTOCOL_WAYLAND_H
//******************************************************************************
//this code is protected by the GNU affero GPLv3
//author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
//                        <digital.ragnarok AT gmail dot com>
//******************************************************************************

//names reference global objects on the server
//ids reference "client binded" objects
#define WL_INVALID_STR "wl_invalid"
#define WL_INVALID_STR_DWS 3

#define WL_INVALID             0
#define WL_DISPLAY             1
#define WL_CALLBACK            2
#define WL_COMPOSITOR          3
#define WL_REGISTRY            4
#define WL_SHM                 5
#define WL_SHM_POOL            6
#define WL_BUFFER              7
#define WL_SEAT                8
#define WL_OUTPUT              9
#define WL_KEYBOARD            10
#define WL_POINTER             11
#define WL_SURFACE             12
#define WL_REGION              13
#define WL_DATA_DEVICE_MANAGER 14
#define WL_SHELL               15
#define WL_SHELL_SURFACE       16
#define WL_UNKNOWN             17

#ifdef WAYLAND_C
void *wl_itfs_strs[]={
  [WL_INVALID]=WL_INVALID_STR,
  [WL_DISPLAY]=WL_DISPLAY_STR,
  [WL_CALLBACK]=WL_CALLBACK_STR,
  [WL_COMPOSITOR]=WL_COMPOSITOR_STR,
  [WL_REGISTRY]=WL_REGISTRY_STR,
  [WL_SHM]=WL_SHM_STR,
  [WL_SHM_POOL]=WL_SHM_POOL_STR,
  [WL_BUFFER]=WL_BUFFER_STR,
  [WL_SEAT]=WL_SEAT_STR,
  [WL_OUTPUT]=WL_OUTPUT_STR,
  [WL_KEYBOARD]=WL_KEYBOARD_STR,
  [WL_POINTER]=WL_POINTER_STR,
  [WL_SURFACE]=WL_SURFACE_STR,
  [WL_REGION]=WL_REGION_STR,
  [WL_DATA_DEVICE_MANAGER]=WL_DATA_DEVICE_MANAGER_STR,
  [WL_SHELL]=WL_SHELL_STR,
  [WL_SHELL_SURFACE]=WL_SHELL_SURFACE_STR
};

u8 wl_itfs_strs_sz[]={
  [WL_INVALID]=sizeof(WL_INVALID_STR),
  [WL_DISPLAY]=sizeof(WL_DISPLAY_STR),
  [WL_CALLBACK]=sizeof(WL_CALLBACK_STR),
  [WL_COMPOSITOR]=sizeof(WL_COMPOSITOR_STR),
  [WL_REGISTRY]=sizeof(WL_REGISTRY_STR),
  [WL_SHM]=sizeof(WL_SHM_STR),
  [WL_SHM_POOL]=sizeof(WL_SHM_POOL_STR),
  [WL_BUFFER]=sizeof(WL_BUFFER_STR),
  [WL_SEAT]=sizeof(WL_SEAT_STR),
  [WL_OUTPUT]=sizeof(WL_OUTPUT_STR),
  [WL_KEYBOARD]=sizeof(WL_KEYBOARD_STR),
  [WL_POINTER]=sizeof(WL_POINTER_STR),
  [WL_SURFACE]=sizeof(WL_SURFACE_STR),
  [WL_REGION]=sizeof(WL_REGION_STR),
  [WL_DATA_DEVICE_MANAGER]=sizeof(WL_DATA_DEVICE_MANAGER_STR),
  [WL_SHELL]=sizeof(WL_SHELL_STR),
  [WL_SHELL_SURFACE]=sizeof(WL_SHELL_SURFACE_STR)
};

u8 wl_itfs_strs_dws[]={
  [WL_INVALID]=WL_INVALID_STR_DWS,
  [WL_DISPLAY]=WL_DISPLAY_STR_DWS,
  [WL_CALLBACK]=WL_CALLBACK_STR_DWS,
  [WL_COMPOSITOR]=WL_COMPOSITOR_STR_DWS,
  [WL_REGISTRY]=WL_REGISTRY_STR_DWS,
  [WL_SHM]=WL_SHM_STR_DWS,
  [WL_SHM_POOL]=WL_SHM_POOL_STR_DWS,
  [WL_BUFFER]=WL_BUFFER_STR_DWS,
  [WL_SEAT]=WL_SEAT_STR_DWS,
  [WL_OUTPUT]=WL_OUTPUT_STR_DWS,
  [WL_KEYBOARD]=WL_KEYBOARD_STR_DWS,
  [WL_POINTER]=WL_POINTER_STR_DWS,
  [WL_SURFACE]=WL_SURFACE_STR_DWS,
  [WL_REGION]=WL_REGION_STR_DWS,
  [WL_DATA_DEVICE_MANAGER]=WL_DATA_DEVICE_MANAGER_STR_DWS,
  [WL_SHELL]=WL_SHELL_STR_DWS,
  [WL_SHELL_SURFACE]=WL_SHELL_SURFACE_STR_DWS
};
#else
extern void *wl_itfs_strs[];
extern u8 wl_itfs_strs_sz[];
extern u8 wl_itfs_strs_dws[];
#endif

//data_device_manager is the biggest
#define WL_ITFS_STRS_DWS_MAX WL_DATA_DEVICE_MANAGER_STR_DWS

#ifdef __GNUC__
#  define UNUSED __attribute__ ((unused))
#else
#  define UNUSED
#endif

static UNUSED u8 wl_strn2itf(void *s,u64 n)
{
  if(!strncmp(s,WL_DISPLAY_STR,n)) return WL_DISPLAY;
  else if(!strncmp(s,WL_CALLBACK_STR,n)) return WL_CALLBACK;
  else if(!strncmp(s,WL_COMPOSITOR_STR,n)) return WL_COMPOSITOR;
  else if(!strncmp(s,WL_REGISTRY_STR,n)) return WL_REGISTRY;
  else if(!strncmp(s,WL_SHM_STR,n)) return WL_SHM;
  else if(!strncmp(s,WL_SHM_POOL_STR,n)) return WL_SHM_POOL;
  else if(!strncmp(s,WL_BUFFER_STR,n)) return WL_BUFFER;
  else if(!strncmp(s,WL_SEAT_STR,n)) return WL_SEAT;
  else if(!strncmp(s,WL_OUTPUT_STR,n)) return WL_OUTPUT;
  else if(!strncmp(s,WL_KEYBOARD_STR,n)) return WL_KEYBOARD;
  else if(!strncmp(s,WL_POINTER_STR,n)) return WL_POINTER;
  else if(!strncmp(s,WL_SURFACE_STR,n)) return WL_SURFACE;
  else if(!strncmp(s,WL_REGION_STR,n)) return WL_REGION;
  else if(!strncmp(s,WL_DATA_DEVICE_MANAGER_STR,n))
    return WL_DATA_DEVICE_MANAGER;
  else if(!strncmp(s,WL_SHELL_STR,n)) return WL_SHELL;
  else if(!strncmp(s,WL_SHELL_SURFACE_STR,n))
    return WL_SHELL_SURFACE;
  return WL_UNKNOWN;
}
#undef UNUSED
#endif
